package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import server.NewsServer;
import serverImp.NewsServerImp;

public class Dle extends HttpServlet {

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		int id=Integer.parseInt(request.getParameter("id"));
		NewsServer ns=new NewsServerImp();
		if(ns.delete(id)>0){
			out.print("<script type='text/javascript'>alert('删除成功');</script>");
			response.sendRedirect("ListServlet");
		}else{
			out.print("<script type='text/javascript'>alert('删除失败');</script>");
			response.sendRedirect("dele.jsp");
		}
		
		
	
	}

}
